<div class="section">

	<div class="section-title">
    	<?php echo $breadcrumb?>
    </div>
    
    <div class="section-content">
    
    	<div class="left">
            
            <h3><?php echo html_entity_decode($heading_title)?></h3>
        
        </div>
        
    	<div class="right">
        	<!--<a class="button" id="printpricelist">Print price</a>&nbsp;-->
            <a class="button" id="printlist">Print</a>&nbsp;
            <?php if($sitemapid != "category") {?>
        	<a class="button" href="<?php echo $DIR_ADD?>">Add</a>&nbsp;
            <a class="button" id="removelist">Delete</a>&nbsp;
            <?php } ?>
            <a class="button" href="index.php"><?php echo $this->document->text['button_cancel']?></a>
        </div>
        <div class="clearer">&nbsp;</div>
        
        <div>
        	<form id="postlist" name="postlist" method="get" action="">
            	<input type="hidden" name="route" value="<?php echo $_GET['route']?>" />
                <input type="hidden" id="sitemapid" name="sitemapid" value="<?php echo $_GET['sitemapid']?>" />
            <fieldset class="fieldset1">
                    <legend>Filter</legend>
                    <p>
                        <span class="formspacing">
                                    <label>Product name :</label>
                            <input type="text" class="text" id="title" name="title" value="<?php echo $_GET['title']?>"/>
                        </span>
                        <span class="formspacing">
                                    <label>Quantity :</label>
                            From <input type="text" class="text number" id="form" name="form" value="<?php echo $_GET['form']?>" style="text-align:right"/>
                            To <input type="text" class="text number" id="to" name="to" value="<?php echo $_GET['to']?>" style="text-align:right"/>
                        </span>
                        
                    </p>
                	<p>
                    	<span class="formspacing">
                                    <label>Sort :</label>
                            <select id="sort" name="sort">
                            	<option value="title-ASC" <?php if($_GET['sort']=="title-ASC") echo 'selected="selected"';?>>Product name a-z</option>
                                <option value="title-DESC" <?php if($_GET['sort']=="title-DESC") echo 'selected="selected"';?>>Product name z-a</option>
                                <option value="quantity-ASC" <?php if($_GET['sort']=="quantity-ASC") echo 'selected="selected"';?>>Quantity min-max</option>
                                <option value="quantity-DESC" <?php if($_GET['sort']=="quantity-DESC") echo 'selected="selected"';?>>Quantity max-min</option>
                            </select>
                        </span>
                    </p>
                    <p><input class="button" type="submit" name="filter" value="Filter"/>&nbsp;<a href="<?php echo $DIR_RESET?>" class="button">Reset</a></p>
                </fieldset>
            <table class="data-table" width="100%">
            
            	<thead>
                	<th>&nbsp;</th>
                    <th width="20%">Product name</th>
                    
                    <th><?php echo $this->document->text['text_price']?></th>
                    <th>Quantity</th>
                    <th><?php echo $this->document->text['text_unit']?></th>
                    <?php if($sitemapid != "category") {?>
                    <th width="10%"><?php echo $this->document->text['text_control']?></th>
                    <?php } ?>
                </thead>
                
                <tbody>
                	<?php foreach($medias as $media) {?>
                	<tr>
                    	<td><?php echo $media['firstcolumn']?>&nbsp;</td>
                        <td><b><?php echo $media['title']?></b>&nbsp;</td>
                        
                        <td align="right"><?php echo $this->string->numberFormate($media['price'])?>&nbsp;</td>
                        <td align="right"><?php echo $this->string->numberFormate($media['quantity'])?>&nbsp;</td>
                        <td><?php echo $media['unit']?>&nbsp;</td>
                        <?php if($sitemapid != "category") {?>
                        <td><?php echo $media['link']?>&nbsp;</td>
                        <?php } ?>
                    </tr>
                    <?php } ?>
                </tbody>
            
            </table>
			</form>
        </div>
        
        <div>
        	<?php echo $nextlink?>
            <?php echo $prevlink?>
            <div class="clearer">&nbsp;</div>
        </div>
        
    </div>

</div>

<script>
var DIR_DELETE = '<?php echo $DIR_DELETE?>';
$(document).ready(function() { 
	$('#removelist').attr('title','Delete selected item').click(function(){deletelist();});  
	$(".number").keyup(function (e)
		{
			//alert(formateNumber($(this).val()))
			num = formateNumber($(this).val().replace(/,/g,""));
			$(this).val(num)
		});
	$(".number").keypress(function (e)
		{
			
		  return isNumber(e.which);
		});
	$("#printlist").click(function()
		{
			//$.post("?route=soft/product/printList", $("#postlist").serialize(), function(data){
			openDialog('?route=soft/product/printList&sitemapid='+$('#sitemapid').val()+'&title='+$('#title').val()+'&form='+$('#form').val()+'&to='+$('#to').val()+'&sort='+$('#sort').val()+'&filter=Filter',800,500);
			//});	
		})
	$("#printpricelist").click(function()
		{
			//$.post("?route=soft/product/printList", $("#postlist").serialize(), function(data){
			openDialog('?route=soft/product/printList&sitemapid='+$('#sitemapid').val()+'&title='+$('#title').val()+'&form='+$('#form').val()+'&to='+$('#to').val()+'&sort='+$('#sort').val()+'&filter=Filter&template=productprintprice.tpl',800,500);
			//});	
		})
});

function deletelist()
{
	$.blockUI({ message: "<h1>Please wait...</h1>" }); 
	$.post(DIR_DELETE, $("#postlist").serialize(), function(data){
		window.location.reload()
	});	
}

</script>
